/*---------------------------------------------------------
    ev_doors.lua - Client Side Doors/Menu
	by Lead4u
---------------------------------------------------------*/

	evorp.doors.stored = {};
	local door = { "func_door_rotating", "prop_door_rotating", "func_door" }
/*---------------------------------------------------------
    Paint Door Info
---------------------------------------------------------*/

	function recieve_paint()
		if !LocalPlayer():Alive() then return end
		 local trace = LocalPlayer():GetEyeTrace()	
		 local ent = trace.Entity
		 if ( !ent:IsValid() or LocalPlayer():GetPos():Distance( ent:GetPos() ) > 200 ) then return end;
			if ( evorp.doors.stored[ent:EntIndex()] ) then
				draw.DrawText( evorp.doors.stored[ent:EntIndex()].type , "ScoreboardText", ScrW() / 2, ScrH()/2 - 30, Color(255, 165, 0, 255),TEXT_ALIGN_CENTER)
				draw.DrawText( evorp.doors.stored[ent:EntIndex()].name .."'s Door." , "ScoreboardText", ScrW() / 2, ScrH()/2 + 15, Color(255, 0, 0, 255),TEXT_ALIGN_CENTER)
				draw.DrawText("( Press F2 to Open Door Menu )" , "ScoreboardText", ScrW() / 2, ScrH()/2 + 32, Color(255, 255, 255, 255),TEXT_ALIGN_CENTER)
			end
			if ( ent:IsValid() and table.HasValue( door, ent:GetClass() ) ) then
				if ( !evorp.doors.stored[ent:EntIndex()] ) then
					draw.DrawText("Unowned" , "ScoreboardText", ScrW() / 2, ScrH()/2 + 15, Color(0, 255, 0, 255),TEXT_ALIGN_CENTER)
					draw.DrawText("( Press F2 to Open Door Menu )" , "ScoreboardText", ScrW() / 2, ScrH()/2 + 32, Color(255, 255, 255, 255),TEXT_ALIGN_CENTER)
				end
			end
		end	
	
	hook.Add( "HUDPaint", "ev_doortext", recieve_paint )
	
	
/*---------------------------------------------------------
    Add / Remove Doors from Client table
---------------------------------------------------------*/
	
	function evorp.doors.Sell( um )
		local DoorID = um:ReadShort()
	
		evorp.doors.stored[DoorID] = nil;
	
	end
	usermessage.Hook("evorp_door_remove" , evorp.doors.Sell, evorp);
	
	
	function evorp.doors.Buy( um )
		local player = um:ReadString()
		local DoorID = um:ReadShort()
		local PlyName = um:ReadString()
		local doortype = um:ReadString()
		
		evorp.doors.stored[DoorID] = {};
		evorp.doors.stored[DoorID].owner = player;
		evorp.doors.stored[DoorID].name = PlyName;
		evorp.doors.stored[DoorID].type = doortype;
	end
	usermessage.Hook("evorp_door_add" , evorp.doors.Buy, evorp);
	
/*---------------------------------------------------------
    Let Server Know Client is Ready
---------------------------------------------------------*/	

	local function userAuthed( ply, stid, unid )
		
		RunConsoleCommand("evorp", "reload" )
		print("Uhm")
	
	end
	hook.Add( "InitPostEntity", "ev_playerauthed", userAuthed )


